/**
 * @author Todd, with minor modifications from Long
 */
package com.dudo.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class HumanDudoPlayer implements DudoPlayer {

	Scanner in = new Scanner(System.in);
	int playerNum;
	int[] playerNumDice; 
	int[] roll;
	ArrayList<Claim> claimList = new ArrayList<Claim>();
	ArrayList<Integer> claimPlayerList = new ArrayList<Integer>();
	int[][] allRolls;
	int totalDice;

	@Override
	public void setPlayer(int playerNum) {
		this.playerNum = playerNum;
	}

	@Override
	public void reportPlayerDice(int[] playerNumDice) {
		this.playerNumDice = playerNumDice;
		System.out.printf("\nPlayer\tDice Remaining\n");
		for (int i = 0; i < playerNumDice.length; i++)
			System.out.printf("%d\t%d\n", i, playerNumDice[i]);
		System.out.println();
		claimPlayerList.clear();
		claimList.clear();
		totalDice = 0;
		for (int numDice : playerNumDice)
			totalDice += numDice;
	}

	@Override
	public void setRoll(int[] roll) {
		this.roll = roll;
		Arrays.sort(roll);
	}

	@Override
	public void reportClaim(int player, Claim claim) {
		claimPlayerList.add(player);
		claimList.add(claim);
		if (player != playerNum)
			System.out.printf("Player %d: %s\n", player, claim.toString());
	}

	@Override
	public void reportAllRolls(int[][] allRolls) {
		this.allRolls = allRolls;
		System.out.println("Player\tRoll");
		for (int i = 0; i < allRolls.length; i++) {
			System.out.print(i + "\t");
			Arrays.sort(allRolls[i]);
			for (int j = 0; j < allRolls[i].length; j++)
				System.out.print(allRolls[i][j] + " ");
			System.out.println();
		}
	}

	@Override
	public Claim getClaim() {
		// Do nothing, wait for input from user
		return null;
	}

	@Override
	public String toString() {
		String s="";
		for (int die : roll) {
			s += die + "\t";
		}
		s += "\n";
		return s;
	}
}
